import requests
from lxml import etree
url = "http://datachart.500.com/ssq/history/newinc/history.php?start=00001&end=99999"
response = requests.get(url)
response = response.text
selector = etree.HTML(response)
for i in selector.xpath('//tr[@class="t_tr1"]'):
    # datetime = i.xpath('td/text()')[0]
    datetime = i.xpath('td/text()')[15]
    phase = i.xpath('td/text()')[0]
    red = i.xpath('td/text()')[1:7]
    blue = i.xpath('td/text()')[7]
    print(datetime, phase, red, blue)
    with open('./lottery.txt', 'a', encoding='utf-8') as fp:
        fp.write(datetime + ' ' + phase + ' ' + str(red) + ' ' + blue + '\n')
